package playground.fibu.ejb;

import java.util.ArrayList;
import java.util.List;

import playground.fibu.ejb.dao.BookingDAO;
import playground.fibu.ejb.dao.DAOFactory;
import playground.fibu.ejb.dao.FibuDAOException;
import playground.fibu.ejb.entity.Account;
import playground.fibu.ejb.entity.Booking;

public class BookingBO {

	private Booking booking;

	public BookingBO() {
		booking = new Booking();
	}

	public BookingBO(Booking b) {
		booking = b;
	}

	public void save() throws FibuDAOException {
		BookingDAO dao = DAOFactory.getDAOFactory(DAOFactory.MYSQL)
				.getBookingDAO();
		dao.save(booking);
	}

	public void delete() throws FibuDAOException {
		BookingDAO dao = DAOFactory.getDAOFactory(DAOFactory.MYSQL)
				.getBookingDAO();
		dao.delete(booking);
	}

	public static List<BookingBO> findAll() throws FibuDAOException{
		List<Booking> dbList = DAOFactory.getDAOFactory(DAOFactory.MYSQL)
				.getBookingDAO().findAll();
		List<BookingBO> result = new ArrayList<BookingBO>();
		for(Booking b : dbList){
			result.add(new BookingBO(b));
		}
		return result;
	}

	public double getAmount() {
		return booking.getAmount();
	}

	public void setAmount(double amount) {
		booking.setAmount(amount);
	}

	public String getText() {
		return booking.getText();
	}

	public void setText(String text) {
		booking.setText(text);
	}

	public Account getDebitAccount() {
		return booking.getDebitAccount();
	}

	public void setDebitAccount(Account debitAccount) {
		booking.setDebitAccount(debitAccount);
	}
}
